import { Admin, User } from '@prisma/client'
import { Request } from 'express'
import { PrismaService } from 'src/common/prisma/prisma.service'

export class ArticelPolicy {
   constructor(private prisma: PrismaService, private request: Request) {}
   async removeArticle(db: string) {
      const model = await this.prisma[db].findFirst({
         where: {
            id: +this.request.params.id
         },
         include: { user: true }
      })

      const admin = (await this.prisma.admin.findFirst()) as Admin

      const user = this.request.user as User

      return user.username == model.user.username || user.username == admin.username
   }
}
